package com.hz.zbl.controller;

import com.hz.zbl.model.dto.StudentScheduleDTO;
import com.hz.zbl.model.request.ApiResponse;
import com.hz.zbl.service.StudentCourseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/edu")
public class StudentCourseController {

    @Resource
    StudentCourseService studentCourseService;


    //选课
    @PostMapping("/student/select-course")
    public String selectCourse(@RequestParam("course_code") String course_code, @RequestParam("student_user_id") int student_user_id){

        int result = studentCourseService.selectCourse(student_user_id,course_code);


        return result > 0 ? ApiResponse.ok(result) : ApiResponse.intError();
    }


    //取消选课
    @PostMapping("/student/cancel-course")
    public String cancelCourse(@RequestParam("course_code") String course_code,
                               @RequestParam("student_user_id") int student_user_id){

        int result = studentCourseService.cancelCourse(student_user_id, course_code);

        return result > 0 ? ApiResponse.ok(result) : ApiResponse.intError();
    }


    //所有课程信息
    @GetMapping("/student/all-courses")
    public String allCourses(){

        return ApiResponse.ok(studentCourseService.allCourse());
    }


    //所指定的所选课程的信息
    @PostMapping("/student/selected-info")
    public String  selectedInfo(@RequestParam("student_user_id") int student_user_id,
                                            @RequestParam("course_code") String course_code ){

        return ApiResponse.ok(studentCourseService.certainCourseInfo(student_user_id, course_code));
    }



    //所有选课的课程信息
    @PostMapping("/student/selected-courses")
    public String selectedCourses(@RequestParam("student_id") Integer student_id){

        return ApiResponse.ok(studentCourseService.selectedCourses(student_id));
    }



    //通过所选学年，学期，查看课表
    @PostMapping("/student/schedule")
    public String schedule(@RequestParam("student_user_id") int student_user_id,
                                             @RequestParam(value = "course_year", required = false) Integer course_year,
                                             @RequestParam(value = "course_semester", required = false) Integer course_semester){

        List<StudentScheduleDTO> res = studentCourseService.studentSchedule(student_user_id, course_year, course_semester);

        return res != null ? ApiResponse.ok(res) : ApiResponse.intError();
    }


}
